﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;

namespace Skecthial.UI.Controls
{
    public partial class NewPost : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string _where = this.Attributes["_where"].ToString().Replace("\"","").Replace("\\","");
            string _when = this.Attributes["_when"].ToString().Replace("\"", "").Replace("\\", "");
            string _with = this.Attributes["_with"].ToString().Replace("\"", "").Replace("\\", "");
            string _who = this.Attributes["_who"].ToString().Replace("\"", "").Replace("\\", "");
            string _what = this.Attributes["_what"].ToString().Replace("\"", "").Replace("\\", "");


            DataTable dt = new DataTable();
            dt.Columns.Add("type");
            dt.Columns.Add("fullname");
            dt.Columns.Add("id");
            dt = GetFiles("people");

            rptWith.DataSource = dt;
            rptWith.DataBind();

            User.Text = "<a class='personPopupTrigger' rel='rel' type='people' name='" + "Boss.png" + "' href='#'><img src='../assets/images/profile.jpg' width='40' height='40' /></a>";

            where.Text = "<a class='personPopupTrigger' rel='rel' type='place' name='" + "onebit_01.png" + "' href='#'><img src='../objects/place/onebit_01.png' width='40' height='40' /></a>";
            string wen = "                                           <table align='center'>                                                                ";
            wen += "                 <tr>                                                                                             ";
            wen += "                     <td class='none only' style='width: 60px; max-height: 60px;'>                                ";
            wen += "                         <div id='timed'>                                                                         ";
            wen += "                             <div style='vertical-align: bottom; min-width: 100%; max-width: 70px; height: 60px;  ";
            wen += "                                 text-align: center; font-size: 11px; line-height: 105%;'>                        ";
            wen += "                                 <div id='dtDay'>                                                                 ";
            wen += "                                     " + DateTime.Now.Day + "                                                                           ";
            wen += "                                 </div>                                                                           ";
            wen += "                                 <br />                                                                           ";
            wen += "                                 <div id='dtMonth' style='font-size: 24px; font-weight: bold; color: #CCC;'>      ";
            wen += "                                    " + DateTime.Now.Month + "                                                                           ";
            wen += "                                 </div>                                                                           ";
            wen += "                                 <br />                                                                           ";
            wen += "                                 <div id='dtYear'>                                                                ";
            wen += "                                     " + DateTime.Now.Year + "                                                                         ";
            wen += "                                 </div>                                                                           ";
            wen += "                             </div>                                                                               ";
            wen += "                         </div>                                                                                   ";
            wen += "                     </td>                                                                                        ";
            wen += "                 </tr>                                                                                            ";
            wen += "             </table>                                                                                             ";
            when.Text = wen;
            what.Text = "<a class='personPopupTrigger' rel='rel' type='activity' name='" + "Oke4 (pail).png" + "' href='#'><img src='../objects/activity/Oke4 (pail).png' width='40' height='40' /></a>";

        }

        protected void rptPosts_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {


            }

        }

        public DataTable GetFiles(string folder)
        {
            DataTable dt2 = new DataTable();
            dt2.Columns.Add("id");
            dt2.Columns.Add("fullname");
            dt2.Columns.Add("type");
            FileInfo fi = new FileInfo(Server.MapPath("~/Objects/" + folder + "/"));
            DirectoryInfo di = fi.Directory;
            FileInfo[] fsi = di.GetFiles();
            int syc = 0;
            //Response.Write("The directory contains the following files and directories:" + di.FullName + "<hr>");
            foreach (FileSystemInfo info in fsi)
            {
                DataRow dr2 = dt2.NewRow();
                dr2[0] = info.Name;//info.Name.Split(' ')[1].TrimEnd(')').TrimStart('(');
                dr2[1] = info.Name; // info.Name.Split(' ')[0].TrimEnd('_');
                dr2[2] = folder;
                dt2.Rows.Add(dr2);
            }

            return dt2;
        }
    }
}